<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket</title>
</head>
<body>
<a href="javascript:WebSocketTest()">运行WebSocket</a>
<div id="messages" style="height: 200px;background: black;color:white"></div>

</body>
<script type="text/javascript">
    var messageContainer=document.getElementById("messages");
    function WebSocketTest() {
        if("WebSocket" in window){
            messageContainer.innerHTML="浏览器支持WebSocket";
            var ws=new WebSocket("ws://localhost:8888/websocket?Id=12345");
            ws.onopen=function () {
                ws.send("onopen")
            };
            ws.onmessage=function (evt) {
                var received_msg=evt.data;
                messageContainer.innerHTML=messageContainer.innerHTML+"<br/>收到的信息："+received_msg;
            }
            ws.onclose=function () {
                messageContainer.innerHTML=messageContainer.innerHTML+"<br/> 连接关闭了";
            }


        }else{
            messageContainer.innerHTML="浏览器不支持WebSocket"
        }
    }
</script>
</html>